// pages/oa/logs/detail.js
var api = require("../../../utils/api.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    logDetailData: '',
    fileUrlList: [],
    //图片附件
    imgUrls: [],
    isShow: false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    var id = options.id;
    var flag = options.flag;
    var currentTab = options.currentTab;
   var userId = wx.getStorageSync('userId');
    wx.setNavigationBarTitle({
      title: "日志详情"
    });
    api.fetchApi2("logManage/queryLogDetailForMobile?id=" + id + "&flag=" + flag, {
    }, "POST").then(res => {
      if (res.data.code == 200) {
        var logDetailData = res.data.data.lawOfficeWorkLog;
        var caseEnclosuresList = res.data.data.caseEnclosuresList;
        that.setData({
          logDetailData: logDetailData,
          fileUrlList: caseEnclosuresList,
        })
        if (caseEnclosuresList.length > 0) {
          that.setData({
            isShow: true,
          })
        }
        if (currentTab == 1) {
          //未读日志设置为已读
          api.fetchApi2("logManage/setReadLogByIdForMobile?logId=" + id + "&userId=" + userId, {
          }, "POST");
        }
      }
    });
  },

  //显示图片
  showImg: function (option) {
    var that = this;
    var fileUrlListResult = that.data.fileUrlList;
    for (var index in fileUrlListResult) {
      that.data.imgUrls[index] = fileUrlListResult[index].url;
    }
    var url = option.currentTarget.dataset.url;
    var imgUrls = that.data.imgUrls;
    wx.previewImage({
      current: url,
      urls: imgUrls
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})